
local _G, vgui = _G, vgui

module "textcapture"

local captured_panel

function Init()
	if _G.g_MouseHackPanel then
		_G.g_MouseHackPanel:Remove()
	end

	_G.g_MouseHackPanel = vgui.Create( "DTextEntry" )
	_G.g_MouseHackPanel:SetSize( 0,0 )
	_G.g_MouseHackPanel:MakePopup() -- MakePopup seems to be the only way to enable the mouse, but it will totally take over the escape menu.
	_G.g_MouseHackPanel:SetKeyboardInputEnabled( false )
	_G.g_MouseHackPanel.OnKeyCodeTyped = function( self, value )
		if captured_panel and captured_panel.OnKeyCodeTyped then
			captured_panel:OnKeyCodeTyped( value )
		end
	end
	_G.g_MouseHackPanel.OnTextChanged = function( self )
		if captured_panel and captured_panel.OnTextEntry then
			captured_panel:OnTextEntry( self:GetValue() )
		end
		
		self:SetText( "" )
	end
end

function Set( panel )
	captured_panel = panel
	if panel then
		_G.g_MouseHackPanel:SetKeyboardInputEnabled( true )
	else
		_G.g_MouseHackPanel:SetKeyboardInputEnabled( false )
	end
end

function Get()
	return captured_panel
end
